package com.na.onlineservey.interview


import com.docu.common.Action
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component
import com.na.onlineservey.InterviewService
import com.na.onlineservey.Interview

@Component("createInterviewAction")
class CreateInterviewAction extends Action {

  @Autowired
  InterviewService interviewInstanceService

  public Object preCondition(Object params, Object object) {
    try {
      Interview interviewInstance = (Interview) object
      if (!interviewInstance.validate()) {
        return null
      }
      return interviewInstance
    } catch (Exception ex) {
    log.error(ex.message)
      return null
    }
  }

  public Object execute(Object params, Object object) {
    try {
      return interviewInstanceService.create(object)
    } catch (Exception ex) {
    log.error(ex.message)
      return null
    }
  }

  public Object postCondition(Object params, Object object) {
    return null
  }
}